/**
 * @param {number} size
 */
var MovingAverage = function(size) {
  this.size = size;
  this.index = 0;
  this.arr = [];
};

/**
 * @param {number} val
 * @return {number}
 */
MovingAverage.prototype.next = function(val) {
  this.arr[this.index] = val;
  this.index = (this.index + 1) % this.size;
  let result = 0;
  for(let i = 0; i < this.arr.length; i++) {
    result += this.arr[i];
  }
  return result / this.arr.length;
};

/**
 * Your MovingAverage object will be instantiated and called as such:
 * var obj = new MovingAverage(size)
 * var param_1 = obj.next(val)
 */
let options = [
  ["MovingAverage", "next", "next", "next", "next"],
[[3], [1], [10], [3], [5]]
];

let obj = new MovingAverage(options[1][0][0]);
let result = [];
for(let i = 1; i < options[0].length; i++) {
  let val = obj.next(options[1][i][0]);
  result.push(val);
}
console.log(result);

